package com.yykj.bank.server.controller;

import com.yykj.bank.client.dto.BankInfoDTO;
import com.yykj.bank.client.form.BankInfoSearchForm;
import com.yykj.bank.server.model.entity.BankInfo;
import com.yykj.bank.server.service.BankInfoService;
import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "总后台--银行相关接口")
@RestController
@RequestMapping("/api/backstage/bank")
public class BankBackstageController {

    @ApiOperation("添加修改银行")
    @PostMapping("/info/edit")
    public ResultVO<BankInfoDTO> editBankInfo(@RequestBody BankInfoDTO bankInfoDTO) {
        return ResultVO.success(bankInfoService.editBankInfo(bankInfoDTO));
    }

    @ApiOperation("银行列表")
    @GetMapping("/info/list")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "code",value = "简码",required = false,type = "String"),
            @ApiImplicitParam(name = "name",value = "银行卡名称",required = false,type = "String"),
            @ApiImplicitParam(name = "currentPage",value = "当前页",defaultValue = "1",type = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "每一页条数",defaultValue = "10",type = "Integer"),
    })
    public ResultVO<PageData<BankInfo>> searchBankInfo(BankInfoSearchForm searchForm){
        return ResultVO.success(bankInfoService.searchBankInfo(searchForm));
    }

    @ApiOperation("删除银行")
    @PostMapping("/info/delete/{code}")
    public ResultVO<BankInfoDTO> deleteBankInfo(@PathVariable String code) {
        bankInfoService.deleteBankInfo(code);
        return ResultVO.success();
    }



    private BankInfoService bankInfoService;

    @Autowired
    public void setBankInfoService(BankInfoService bankInfoService) {
        this.bankInfoService = bankInfoService;
    }
}
